package app.view.component 
{
	import app.facade.App;
	import app.view.component.moment.Module;
	import com.greensock.loading.LoaderMax;
	import com.hutra.utils.Cache;
	import com.hutra.utils.Repareloader;
	import com.temple.core.CoreMovieClip;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import com.greensock.*;
	import com.greensock.loading.*;
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.display.*;
	import org.osflash.thunderbolt.Logger;

	/**
	 * ...
	 * @author ria.go.vn
	 */
	public class Datas extends CoreMovieClip{
		
		private var list:Array;
		private var asset:Array;
		private var data:Array;
		
		public function Datas(){
			asset = new Array();
			data = new Array();
		}
		public function setList(value:Array):void {
			list = value;
			TweenMax.delayedCall(1, loading);
		}
		public function loading():void {
			var queue:LoaderMax = new LoaderMax( { name:App.DATAS,  auditSize :false, onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler, maxConnections:list.length });
			for (var i:int = 0; i < list.length; i++){
				var url:String = String(list[i].url);
				var key:String = String(list[i].key);
				var est:Number = Number(list[i].est);
				var typ:Number = Number(list[i].type);
				if(typ==0) queue.append( new MP3Loader(url, { name:key, estimatedBytes:est, autoPlay:false}));
				if(typ==1) queue.append( new SWFLoader(url, { name:key, estimatedBytes:est}));
			}
			queue.load();
		}
		private function progressHandler(event:LoaderEvent):void {
			sendNotification(App.LOADING_BUFFERING, { value:event.target.progress*100 } );
		}
		private function completeHandler(event:LoaderEvent):void {
			TweenMax.delayedCall(1, waitTimeDone);
		}
		private function waitTimeDone():void {
			sendNotification(App.ASSET_LOAD_DONE); 
		}
		private function errorHandler(event:LoaderEvent):void {
			sendNotification(App.SHOW_ERROR,{value:"Can't not load data"}); 
		}
		
		
	}

}